package com.order.provider.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestSentinelController {

    private static final Logger log = LoggerFactory.getLogger(TestSentinelController.class);

    @GetMapping("/provider/sentinel/test/{message}")
    @SentinelResource(value = "providerSentinelTest", blockHandler = "handlerBlockHandler")
    public String providerSentinelTest(@PathVariable("message") String message) {
        log.info("providerSentinelTest服务正常");
        return "providerSentinelTest服务正常 ：" + message;
    }
    
    public String handlerBlockHandler(@PathVariable("message") String message, BlockException exception) {
        return "providerSentinelTest服务不可用，" + "触发sentinel流控配置规则"+"\t"+"o(╥﹏╥)o";
    }
}
